package 练习题;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * @author Liangyaoyun
 */
public class MyQueue {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        Deque<Integer> queue;
        queue=new LinkedList<>();
        System.out.println("请输入你要入队的元素:");
        int i;
        i=scanner.nextInt();
        queue.add(i);
        i=scanner.nextInt();
        queue.add(i);
        i=scanner.nextInt();
        queue.add(i);
        i=scanner.nextInt();
        queue.add(i);
        i=scanner.nextInt();
        queue.add(i);
        i=scanner.nextInt();
        queue.add(i);
        System.out.print("显示队尾元素:");
        System.out.println(queue.peekLast());
        System.out.print("弹出队首元素:");
        System.out.println(queue.poll());
        System.out.print("显示队首元素:");
        System.out.println(queue.peek());
        System.out.print("显示队列长度:");
        System.out.println(queue.size());
        System.out.print("遍历队列:");
        while( !queue.isEmpty()){
           System.out.print(queue.poll()+" ");
       }
        System.out.println();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        queue.offer(4);
        queue.offer(5);
        queue.offer(6);
        System.out.println("清空队列");
        queue.clear();
    }
}
